package com.fancy.projecty.pojo;


import java.util.HashMap;

/**
 * 自定义map返回值
 * 解决返回值驼峰问题
 */
public class CamelKeyMap extends HashMap {
	@Override
	public Object put(Object key, Object value) {
//		key = StringUtil.camelCaseName(String.valueOf(key));
		key = this.camelCaseName(String.valueOf(key));
		return super.put(key, value);
	}


	/**
	 * 转换为驼峰
	 *
	 * @param underscoreName
	 * @return
	 */
	private String camelCaseName(String underscoreName) {
		StringBuilder result = new StringBuilder();
		if (underscoreName != null && underscoreName.length() > 0) {
			boolean flag = false;
			for (int i = 0; i < underscoreName.length(); i++) {
				char ch = underscoreName.charAt(i);
				if ("_".charAt(0) == ch) {
					flag = true;
				} else {
					if (flag) {
						result.append(Character.toUpperCase(ch));
						flag = false;
					} else {
						result.append(ch);
					}
				}
			}
		}
		return result.toString();
	}


}
